import Box1 from "./Box1";
import Box2 from "./Box2";
import Box3 from "./Box3";
/**
 * 掉落盒子脚本，实现盒子碰撞及回收流程
 */
export default class Box extends Laya.Script {
    /**刚体对象引用 */
    private _rig: Laya.RigidBody;

    /** @prop {name:nextLevelBox,tips:"下一等级盒子",type:Prefab}*/
    nextLevelBoxPrefab: Laya.Prefab;
    nextLevelBoxSprite: Laya.Sprite;

    constructor() { super(); }

    onEnable(): void {
        /**获得组件引用，避免每次获取组件带来不必要的查询开销 */
        this._rig = this.owner.getComponent(Laya.RigidBody);

        var owner: Laya.Sprite = this.owner as Laya.Sprite;
        
        if(this.nextLevelBoxPrefab != null){
            this.nextLevelBoxSprite = Laya.Pool.getItemByCreateFun("nextLevelBox", this.nextLevelBoxPrefab.create, this.nextLevelBoxPrefab);
            if(owner.parent){
                owner.parent.addChild(this.nextLevelBoxSprite);
            }
        }
    }

    onUpdate(): void {
       
    }

    onTriggerEnter(other: any, self: any, contact: any): void {
        Laya.SoundManager.playSound("sound/destroy.wav");
    }

    onDisable(): void {
        //盒子被移除时，回收盒子到对象池，方便下次复用，减少对象创建开销。
        Laya.Pool.recover("box", this.owner);
    }
}